package bsh.dyn;

import bsh.BytecodeGenerator;
import bsh.CompiledScript;

/**
 * Common interface to methods, constructors and .length field of arrays.
 * 
 * @author takeshi
 */
public interface Invocable extends BytecodeGenerator {

    /**
     * Invokes the method / constructor
     * 
     * @param script the {@link CompiledScript}
     * @param target the method target. May be <code>null</code> if the method is static or is a constructor
     * @param parameters the parameters to be passed. Should almost never be null
     * @return the return value if any
     * @throws Throwable the throwable
     */
    Object invoke(CompiledScript script, Object target, Object[] parameters) throws Throwable;

    /**
     * Return an array with the declared parameter types for this {@link Invocable}
     * 
     * @return array of {@link DeclaredParameterType}. Modifications on this array are NOT reflected back to this {@link Invocable}
     */
    DeclaredParameterType[] getParameterTypes();

    /**
     * @return true if this {@link Invocable} is a varargs
     */
    boolean isVarargs();

    /**
     * @return boolean. If true, this Invocable can be compiled down to bytecode
     */
    boolean isCompilable();

}
